package com.ruoyi.project.hidden.hiddenOrder.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.hidden.hiddenOrder.domain.HiddenOrder;
import com.ruoyi.project.hidden.hiddenOrder.service.IHiddenOrderService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 隐患单据Controller
 * 
 * @author ruoyi
 * @date 2021-01-23
 */
@Controller
@RequestMapping("/hidden/hiddenOrder")
public class HiddenOrderController extends BaseController
{
    private String prefix = "hidden/hiddenOrder";

    @Autowired
    private IHiddenOrderService hiddenOrderService;

    @RequiresPermissions("hidden:hiddenOrder:view")
    @GetMapping()
    public String hiddenOrder()
    {
        return prefix + "/hiddenOrder";
    }

    /**
     * 查询隐患单据列表
     */
    @RequiresPermissions("hidden:hiddenOrder:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(HiddenOrder hiddenOrder)
    {
        startPage();
        List<HiddenOrder> list = hiddenOrderService.selectHiddenOrderList(hiddenOrder);
        return getDataTable(list);
    }

    /**
     * 导出隐患单据列表
     */
    @RequiresPermissions("hidden:hiddenOrder:export")
    @Log(title = "隐患单据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(HiddenOrder hiddenOrder)
    {
        List<HiddenOrder> list = hiddenOrderService.selectHiddenOrderList(hiddenOrder);
        ExcelUtil<HiddenOrder> util = new ExcelUtil<HiddenOrder>(HiddenOrder.class);
        return util.exportExcel(list, "hiddenOrder");
    }

    /**
     * 新增隐患单据
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存隐患单据
     */
    @RequiresPermissions("hidden:hiddenOrder:add")
    @Log(title = "隐患单据", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(HiddenOrder hiddenOrder)
    {
        return toAjax(hiddenOrderService.insertHiddenOrder(hiddenOrder));
    }

    /**
     * 修改隐患单据
     */
    @GetMapping("/edit/{orderId}")
    public String edit(@PathVariable("orderId") Long orderId, ModelMap mmap)
    {
        HiddenOrder hiddenOrder = hiddenOrderService.selectHiddenOrderById(orderId);
        mmap.put("hiddenOrder", hiddenOrder);
        return prefix + "/edit";
    }

    /**
     * 修改保存隐患单据
     */
    @RequiresPermissions("hidden:hiddenOrder:edit")
    @Log(title = "隐患单据", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(HiddenOrder hiddenOrder)
    {
        return toAjax(hiddenOrderService.updateHiddenOrder(hiddenOrder));
    }

    /**
     * 删除隐患单据
     */
    @RequiresPermissions("hidden:hiddenOrder:remove")
    @Log(title = "隐患单据", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(hiddenOrderService.deleteHiddenOrderByIds(ids));
    }
}
